package org.apogeescience.connector.databases;

import org.apogeescience.config.DatabaseConfiguration;
import org.apogeescience.connector.DatabaseType;

/**
 * DatabaseFactory will generate the correct instance of the database which was defined in the configuration file
 * @author Isaac
 *
 */
public class DatabaseFactory {
	
	/**
	 * Gets the instance of the database
	 * @param dbConfig Database configuration which holds the database type
	 * @return
	 */
	public static IDatabase getDatabase(DatabaseConfiguration dbConfig) {
		DatabaseType type = DatabaseType.valueOf(dbConfig.getDatabaseType());
		switch (type) {
		case MYSQL:
			return new MySqlDatabase(dbConfig);
		case ORACLE:
			return new OracleDatabase(dbConfig);
		case SQLSERVER:
			return new SqlServerDatabase(dbConfig);
		case XML:
			return new XMLDatabase(dbConfig);
		default:
			return null;
		}
	}
}
